package com.lc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.TInterposeFollowupVisitMapper;
import com.guigu.mapper.TInterposeSchemeMapper;
import com.guigu.viwe.PageVo;
import com.lc.service.WorkloadService;
import com.lc.vo.Interventionprogramview;
import com.lc.vo.interventionTotalView;
import com.lc.vo.interventview;
import com.lc.vo.returnView;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WorkloadServiceimpl implements WorkloadService {

    @Resource
    private TInterposeSchemeMapper tInterposeSchemeMapper;

    @Resource
    private TInterposeFollowupVisitMapper tInterposeFollowupVisitMapper;
    @Override
    public Interventionprogramview queryInterventionprogram(Interventionprogramview view) {
        view.setStartinterdate(view.getInterventdate().get(0));
        view.setEndinterdate(view.getInterventdate().get(1));
        //查询干预方案
        List<interventview> queryinterposeschemecount = this.tInterposeSchemeMapper.queryinterposeschemecount(view);
        view.setInterventviews(queryinterposeschemecount);

        //查询干预回访
        List<returnView> querytjfx = this.tInterposeFollowupVisitMapper.querytjfx(view);
        view.setReturnViews(querytjfx);
        return view;
    }

    @Override
    public    List<interventionTotalView> quersumliangService() {
        List<interventionTotalView> ganyuhuif = this.tInterposeFollowupVisitMapper.selectsumTInterposeFollowupVisi();
        List<interventionTotalView> ganyufan = this.tInterposeSchemeMapper.selectsumTInterposeScheme();
        Map<Integer,interventionTotalView> map=new HashMap<Integer,interventionTotalView>();
        for (interventionTotalView x:ganyufan){
            for(interventionTotalView y:ganyuhuif){
                if(x.getUserid()==y.getUserid()){
                    map.put(x.getUserid(),new interventionTotalView(x.getFullname(),x.getGanyufangan(),y.getGanyuhuifang(),x.getUserid()));
                }else{
                   if(!map.containsKey(x.getUserid())){
                       map.put(x.getUserid(),new interventionTotalView(x.getFullname(),x.getGanyufangan(),x.getGanyuhuifang(),x.getUserid()));
                   }
                   if(!map.containsKey(y.getUserid())){
                       map.put(y.getUserid(),new interventionTotalView(y.getFullname(),y.getGanyufangan(),y.getGanyuhuifang(),y.getUserid()));
                   }
                }
            }
        }
        List<interventionTotalView> v=new ArrayList<interventionTotalView>();
        map.forEach((key, value) -> {
           v.add(value);
        });
        return v;
    }
}
